home *** CD-ROM | disk | FTP | other *** search
- ;void print_forward(strg,field_size);
- ; char *strg;
- ; unsigned short field_size;
-
- EXTRN _memory_model:byte
- EXTRN _error_code:byte
- EXTRN _time_out:byte
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _print_forward
- _print_forward proc near
- jmp short start ;jmp over local data
- delay dw ? ;
- target dw ? ;
- start: push bp ;
- mov bp,sp ;set stack frame
- push si ;
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: push ds ;save DS
- mov ah,1 ;BIOS func to init prtr
- sub dx,dx ;choose LPT1
- int 17h ;initialize the prtr port
- sub ax,ax ;clear AX
- mov es,ax ;point ES to 0000:0000
- mov dx,es:[408h] ;get LPT1 base address
- mov _error_code,1 ;1 = printer error
- mov al,_time_out ;get _time_out seconds
- cmp _memory_model,2 ;data near or far?
- jb A1 ;jump if near
- lds si,dword ptr[bp+4] ;DS:SI pts to Strg
- jmp short A2 ;
- A1: mov si,[bp+4] ;near case
- A2: or al,al ;don't allow zero seconds
- jnz A3 ;
- mov al,3 ;default to 3 seconds
- A3: mov cl,18 ;18 ticks per second
- mul cl ;
- mov cs:delay,ax ;save count
- sub cx,cx ;clear CX
- push si ;count string length...
- A4: cmp byte ptr [si],0 ;end of string?
- je A5 ;jump if so
- inc si ;forward string ptr
- inc cx ;inc length counter
- jmp short A4 ;loop
- A5: pop si ;restore ptr to start of string
- jcxz L3 ;jump if string null
- mov ax,[bp+6] ;Field Size
- or ax,ax ;test for zero
- jz L5 ;quit if zero
- cmp cx,ax ;is Strg larger?
- jna L1 ;jump ahead if not
- mov cx,ax ;strg len = field size
- sub ax,ax ;clear AX
- mov [bp+6],ax ;write 0 chars after strg
- jmp short L2 ;jump ahead
- L1: sub ax,cx ;field size - strg length
- mov [bp+6],ax ;save on stack
- L2: mov al,[si] ;get a character
- inc si ;forward ptr for next time
- call Writeit ;go write character
- or ah,ah ;test for error
- jz L5 ;quit if error
- loop L2 ;go do next char
- L3: sub cx,cx ;clear CX
- mov cl,[bp+6] ;number spc to print
- jcxz L5 ;quit if null
- L4: mov al,' ' ;space char
- call Writeit ;go print it
- or ah,ah ;test for error
- jz L5 ;quit if error
- loop L4 ;go do next space
- pop ds ;
- dec _error_code ;0 = no error
- jmp short L6 ;
- L5: pop ds ;
- L6: pop si ;
- pop bp ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _print_forward endp
- Writeit PROC
- out dx,al ;send to output data register
- inc dx ;forward to status register
- push cx ;save string counter
- call GetBiosCount ;get timer reading
- mov bx,cx ;make copy
- add cx,cs:delay ;add delay count
- cmp bx,cx ;if timer doesn't turn over...
- jb L7 ;go ahead
- mov cx,cs:delay ;otherwise, extend delay
- L7: mov cs:target,cx ;save target count on stack
- Wait: in al,dx ;get status value
- test al,8 ;test for printer error
- jz Error ;
- test al,80h ;test for Printer Ready
- jnz Ready ;jump if ready
- Error: call GetBiosCount ;
- cmp cx,cs:target ;compare to target
- jb Wait ;
- pop cx ;restore string counter
- mov ah,0 ;return code for failure
- jmp short L8 ;return
- Ready: pop cx ;restore string counter
- inc dx ; output control register
- mov al,13 ;bits for strobe signal
- out dx,al ;send the signal
- dec al ;change to strobe OFF
- out dx,al ;send the signal
- dec dx ;point back to
- dec dx ; base address
- mov ah,1 ;return code for success
- L8: ret ;
- Writeit endp
- GetBIOSCount PROC
- push dx ;return value in CX:DX
- push ax ;
- sub ah,ah ;function number
- int 1ah ;get timer count
- mov cx,dx ;low word in CX
- pop ax ;
- pop dx
- ret
- GetBIOSCount endp
- Writeit endp
- _TEXT ENDS
- END